package com.scau.vo;

import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

/**
 * Payment entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "payment", catalog = "db_hairdressingpos")
public class Payment implements java.io.Serializable {

	// Fields

	private Integer id;
	private SaleOrder saleOrder;
	private Admin admin;
	private String amount;
	private Timestamp payDateTime;
	private Integer payTransactionNo;
	private String payType;
	private String paymentNo;
	private String stuffName;

	// Constructors

	/** default constructor */
	public Payment() {
	}

	/** minimal constructor */
	public Payment(SaleOrder saleOrder, Admin admin, String amount,
			Timestamp payDateTime, String payType, String paymentNo) {
		this.saleOrder = saleOrder;
		this.admin = admin;
		this.amount = amount;
		this.payDateTime = payDateTime;
		this.payType = payType;
		this.paymentNo = paymentNo;
	}

	/** full constructor */
	public Payment(SaleOrder saleOrder, Admin admin, String amount,
			Timestamp payDateTime, Integer payTransactionNo, String payType,
			String paymentNo, String stuffName) {
		this.saleOrder = saleOrder;
		this.admin = admin;
		this.amount = amount;
		this.payDateTime = payDateTime;
		this.payTransactionNo = payTransactionNo;
		this.payType = payType;
		this.paymentNo = paymentNo;
		this.stuffName = stuffName;
	}

	// Property accessors
	@Id
	@GeneratedValue
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "saleOrderNo", nullable = false)
	@NotFound(action=NotFoundAction.IGNORE)
	/*
	 * 该注解解决的bug，下面网址有介绍
	 * http://www.cnblogs.com/hy928302776/archive/2013/04/17/3027049.html
	 */	
	public SaleOrder getSaleOrder() {
		return this.saleOrder;
	}

	public void setSaleOrder(SaleOrder saleOrder) {
		this.saleOrder = saleOrder;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "stuff", nullable = false)
	public Admin getAdmin() {
		return this.admin;
	}

	public void setAdmin(Admin admin) {
		this.admin = admin;
	}

	@Column(name = "amount", nullable = false)
	public String getAmount() {
		return this.amount;
	}

	public void setAmount(String amount) {
		this.amount = amount;
	}

	@Column(name = "payDateTime", nullable = false, length = 19)
	public Timestamp getPayDateTime() {
		return this.payDateTime;
	}

	public void setPayDateTime(Timestamp payDateTime) {
		this.payDateTime = payDateTime;
	}

	@Column(name = "payTransactionNo")
	public Integer getPayTransactionNo() {
		return this.payTransactionNo;
	}

	public void setPayTransactionNo(Integer payTransactionNo) {
		this.payTransactionNo = payTransactionNo;
	}

	@Column(name = "payType", nullable = false)
	public String getPayType() {
		return this.payType;
	}

	public void setPayType(String payType) {
		this.payType = payType;
	}

	@Column(name = "paymentNo", nullable = false, length = 191)
	public String getPaymentNo() {
		return this.paymentNo;
	}

	public void setPaymentNo(String paymentNo) {
		this.paymentNo = paymentNo;
	}

	@Column(name = "stuffName")
	public String getStuffName() {
		return this.stuffName;
	}

	public void setStuffName(String stuffName) {
		this.stuffName = stuffName;
	}
	
	@Override
	public String toString() {
		return "{\"id\":" + id 
				+ ", \"adminName\":" + "\"" + admin.getName() + "\""
				+ ", \"adminId\":" + admin.getId()
				//+ ", \"saleOrderNo\":" + "\"" + saleOrder.getSaleOrderNo() + "\""
				+ ", \"paymentNo\":" + "\"" + paymentNo + "\""
				+ ", \"amount\":" + "\"" + amount + "\""
				+ ", \"payType\":" + "\"" +payType+ "\""
				+ ", \"payDateTime\":" + "\"" +payDateTime+ "\""
				+ "}";
	}

}